package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.DTO.CartGoodsSellerDTO;
import com.example.demo.pojo.Cart;
import com.example.demo.pojo.Pets;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper  {
	@Insert("INSERT INTO cart (goodsID, userID, num, price, createTime, sellerID, totalPrice) " +
			"VALUES (#{goodsID}, #{userID}, #{num}, #{price}, #{createTime}, #{sellerID}, #{totalPrice}) " +
			"ON DUPLICATE KEY UPDATE num = num + VALUES(num)")
	void insert(Cart cart);
    @Select("SELECT * FROM cart WHERE userID=#{userID}")
	List<Cart> list(Integer userID);

	@Select("SELECT * FROM cart WHERE userID = #{userID} AND selected = 1")
	List<Cart> getSelectedCartItemsByUser(Integer userID);
	@Select("SELECT goodsID, sellerID, num,selected FROM cart WHERE userID = #{userID}")
	List<CartGoodsSellerDTO> findGoodsAndSellerIDsByUserID(Integer userID);

	@Select("SELECT * FROM cart WHERE userID = #{userID} AND sellerID = #{sellerID}")
	List<Cart> findByUserAndSellerID(@Param("userID") Integer userID, @Param("sellerID") Integer sellerID);

	@Update("UPDATE cart SET selected = #{selected} WHERE goodsID = #{goodsID} AND userID = #{userID}")
	void updateCartItemSelectionStatus(@Param("goodsID") Integer goodsID, @Param("userID") Integer userID, @Param("selected") Boolean selected);

	@Delete("DELETE FROM cart WHERE id = #{cartID}")
	void deleteById(Integer cartID);
}